package com.adroiti.texasholdem.engine.combinations;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import com.adroiti.texasholdem.Card;
import com.adroiti.texasholdem.Color;

public class StraightFlush extends AbstractCombination {

	private Straight straight;

	public StraightFlush() {
		this(new Straight());
	}

	public StraightFlush(Straight straight) {
		this.straight = straight;
	}

	@Override
	public int getRank(List<Card> player, List<Card> table) {

		List<Card> cards = new ArrayList<Card>(player);
		cards.addAll(table);

		List<Card> colors = new LinkedList<Card>();
		int rank = 0;
		for (Color color : Color.values()) {
			for (Card card : cards) {
				if (card.getColor().equals(color)) {
					colors.add(card);
				}
			}

			if (cards.size() >= 5) {
				int rn = straight.getRank(colors, new LinkedList<Card>());
				if (rn > rank) {
					rank = rn;
				}
			}
			colors.clear();
		}
		return rank;
	}

	@Override
	public String getName() {
		return "StraighFlush";
	}

	@Override
	public int getCombinationRank() {
		return 9;
	}

}
